<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends CommonController {
    public function index(){
    	// 获取排行
    	$rankNews = $this->getRanks();
    	// var_dump($rankNews);die;

    	// 获取首页大图
    	$topPicNews = D("PositionContent")->select(['status'=>1,'position_id'=>1],1);
    	// 首页小图
    	$topSmailNews = D("PositionContent")->select(['status'=>1,'position_id'=>2],3);
    	// 获取文章信息
    	$listNews = D("News")->select([
    			'status'=>1,
    			'thumb'=>['neq',''],
    			],30);
    	$advNews = D("PositionContent")->select(['status'=>1,'position_id'=>3],2);
    	$this->assign('result',[
    			'topPicNews'=>$topPicNews,
    			'topSmailNews'=>$topSmailNews,
    			'listNews'=>$listNews,
    			'advNews'=>$advNews,
    			'rankNews'=>$rankNews,
    			'catId'=>0,

    			]);
        // 生成页面静态化
        if($type == 'buildHtml'){
            $this->buildHtml('index',HTML_PATH,'Index/index');
        }else{
            $this->display();    
        }
    }
    public function build_html()
    {
    	$this->index('buildHtml');
        return show(1,'首页缓存生成成功');
    }
    public function crontab_bulid_html()
    {
        $this->index('buildHtml');
    }
    public function getCount()
    {
        if(!$_POST){
            return show(0,'没有任何内容');
        }
        $newsIds = array_unique(($_POST));
        try{
            $list = D("News")->getNewsByNewsIdIn($newsIds);
        }catch(Exception $e){
            return show(0,$e->getMessage());
        }
        $data = [];
        foreach($list as $k=>$v){
            $data[$v['news_id']] = $v['count'];
        }
        // var_dump($list);die;
        return show(1,'success',$data);
    }
}